package com.BlackMesa.models;

import org.junit.Test;
import android.test.ActivityInstrumentationTestCase2;
import com.BlackMesa.controllers.TodoListActivity;

public class UserTest extends
		ActivityInstrumentationTestCase2<TodoListActivity> {
	private User user, u;
	private Task t1, t2, t3, t4, list;
	private Category cat, cat1, cat2, cat3, cat4;

	public UserTest() {
		super("com.BlackMesa.controllers", TodoListActivity.class);

	}

	public void setUp() throws Exception {
		super.setUp();
		user = new User("Name", "Username", "Email@email.com", "Password");
		u = new User("patrick", "pat", "p@this.com", "p");
		list = new Task("list");
	}

	/* Tyler */
	@Test
	public void testCheckPass() {
		assertFalse(user.checkPass(null));
		assertFalse(user.checkPass(""));
		assertTrue(user.checkPass("Password"));
		assertFalse(user.checkPass("password"));
	}

	/* Tyler */
	@Test
	public void testAddTaskCategoryTask() {
		cat1 = new Category("cat1", 0);
		cat2 = new Category("cat2", 0);
		cat3 = new Category("cat3", 0);
		t1 = new Task("t1");
		t2 = new Task("t2");
		t3 = new Task("t3");
		t4 = new Task("t4");
		user.addTask(cat1, t2);
		user.addTask(cat2, t1);
		user.addTask(cat2, t3);
		user.addTask(cat3, t4);

		assertSame(t1, cat2.getTasks().get(0));
		assertSame(t2, cat1.getTasks().get(0));
		assertNotNull(user.getActiveCategory());
		assertTrue(user.AllTask().containsTask(t1));
		assertTrue(user.IncompleteTasks().containsTask(t1));

	}

	/* Tyler */
	@Test
	public void testGetCategoryWithStringString() {
		User myUser = new User("", "", "", "");

		Category cat1 = new Category("Cat1", 0);
		Category cat2 = new Category("Cat2", 0);

		myUser.addCategory(cat1);
		myUser.addCategory(cat2);

		assertEquals(cat1, myUser.getCategoryWithString("Cat1"));
		assertEquals(cat2, myUser.getCategoryWithString("Cat2"));
		assertNull(myUser.getCategoryWithString("Cat3"));
	}
	/*Tyler*/
	@Test
	public void testAddCategoryCategory() {
		User myUser = new User("", "", "", "");
		
		Category cat1 = new Category("Cat1", 0);
		Category cat2 = null;
		
		myUser.addCategory(cat1);
		assertTrue(myUser.containsCategory(cat1));
		myUser.addCategory(cat2);
		assertFalse(myUser.containsCategory(cat2));
		
	}

	/* Patrick */
	@Test
	public void testContainsCategoryCategory() {
		cat1 = new Category("work", 0);
		Task t = new Task("task1", null, cat1, null, null, null);
		Task tt = new Task("task2", null, cat1, null, null, null);
		assertEquals(cat1, u.createCategory("work", 0, t));
		assertNotSame(cat1, u.createCategory("home", 0, tt));
	}

	/* Cody */
	@Test
	public void testCreateCategory() {
		cat = new Category("Groceries", 0);
		cat2 = new Category("Homework", 0);
		cat3 = new Category("Workout", 0);

		cat3 = user.createCategory("Workout", 0, list);
		user.addCategory(cat3);

		assertEquals(cat, user.createCategory("Groceries", 0, list));
		assertNotSame(cat, user.createCategory(null, 0, null));
		assertTrue(user.containsCategory(cat3));
		assertFalse(user.containsCategory(new Category("notcat4", 0)));
	}

	/* Cody */
	@Test
	public void testDeleteCategoryCategoryBoolean() {
		cat = new Category("Groceries", 0);
		cat2 = new Category("Homework", 0);
		cat3 = new Category("Workout", 0);
		cat4 = null;

		cat3 = user.createCategory("Workout", 0, list);
		user.addCategory(cat3);
		user.addCategory(cat);
		user.deleteCategory(cat3, true);
		user.deleteCategory(cat2, true);
		user.deleteCategory(cat4, false);

		cat.addTask(list, true);
		user.deleteCategory(cat, false);

		assertFalse(user.containsCategory(cat3));
		assertFalse(user.containsCategory(cat2));
		assertFalse(user.containsCategory(cat4));
		assertFalse(user.AllTask().containsTask(list));
	}
	/*Nick*/
	@Test
	public void testSetActiveCategoryWithStringString() {
		User newUser = new User("","","","");
		Category cat1 = new Category("cat1",0);
		Category cat2 = new Category("cat2",0);
		newUser.addCategory(cat1);
		newUser.addCategory(cat2);
		
		newUser.setActiveCategoryWithString(cat1.getName());
		assertSame(cat1, newUser.getActiveCategory());
		assertNotSame(cat2, newUser.getActiveCategory());
		newUser.setActiveCategoryWithString(null);
		assertSame(newUser.AllTask(),newUser.getActiveCategory());
	}

	/*Cody*/
	@Test
	public void testGetLocationWithName(){
		String name = new String("Kroger");
		assertNotSame(name, user.getLocationWithName(name));
	}

}